<template>
  <div>
    <el-tag>模切</el-tag>
    <el-checkbox @change="clickToChange()">需要</el-checkbox>
    <br/>
      <el-select v-model="moqie.zhonglei" :disabled="disable"
               placeholder="请选择" class="length" size="small">
        <el-option v-for="(item) in option.moqie_option" :key="item" :label="item" :value="item"></el-option>
      </el-select>
      <span>模数:</span>
      <el-input v-model="moqie.moshu" :disabled="disable"
                placeholder="输入损耗数" size="small" class = "length" @change="transferValue"></el-input>
      <span>刀模费:</span>
      <el-input v-model="moqie.daomofei" :disabled="disable"
                placeholder="输入损耗数" size="small" class = "length"></el-input>
      <br/>
    <template v-if="getRole()">
    <el-tag type="warning" class="cost">成本: {{computeCost()}}</el-tag>
    </template>
    </div>

</template>

<script>
export default {
  name: 'Moqie',
  props: ['Q', 'x', 'y', 'confirm'],
  data () {
    return {
      disable: true,
      moqie: {
        moshu: 0,
        zhonglei: '',
        daomofei: ''
      },
      option: {
        moqie_option: ['吊牌', '卡盒', '坑盒', '对裱卡盒']
      }
    }
  },
  methods: {
    transferValue () {
      this.$emit('transferM', this.moqie.moshu)
    },
    computeCost () {
      let q = parseInt(this.Q)
      let cost = 0
      let costStr = ''
      let dao = parseInt(this.moqie.daomofei)
      let x15 = parseInt(this.x) + 15
      let y15 = parseInt(this.y) + 15
      let x10 = parseInt(this.x) + 10
      let y10 = parseInt(this.y) + 10
      switch (this.moqie.zhonglei) {
        case '吊牌':
          cost = 0.1 * q + 30 <= 120 ? 120 + dao : 0.1 * q + 30 + dao
          costStr = 0.1 * q + 30 <= 120 ? `120 + ${dao} = ${cost}` : `0.1 × ${q} + 30 + ${dao} = ${cost}`
          break
        case '对裱卡盒':
          if (0.07 * q + 30 <= 120) {
            costStr = `120`
          } else if (this.moqie.moshu <= 6 || (x15 <= 600 && y10 <= 720) || (x10 <= 720 && y15 <= 600)) {
            cost = 0.07 * q + 30 + dao
            costStr = `0.07 × ${q} + 30 + ${dao} = ${cost}`
          } else if (this.moqie.moshu > 6 || ((x15 > 600 && x15 <= 720) && (y10 > 720 && y10 <= 1020)) || ((x10 > 720 && x10 <= 930) && (y15 > 600 && y15 <= 635))) {
            cost = 0.08 * q + 30 + dao
            costStr = `0.08 × ${q} + 30 + ${dao} = ${cost}`
          } else if (((x15 > 635 && x15 < 720) && (y10 > 930 && y10 < 1020)) || ((x10 > 930 && x10 < 1020) && (y15 > 635 && y15 < 720))) {
            cost = 0.09 * q + 30 + dao
            costStr = `0.09 × ${q} +30 + ${dao} = ${cost}`
          }
          break
        case '卡盒':
          if (0.07 * q + 30 <= 120) {
            costStr = `120`
          } else if (this.moqie.moshu <= 6 || (x15 <= 600 && y10 <= 720) || (x10 <= 720 && y15 <= 600)) {
            cost = 0.07 * q + 30 + dao
            costStr = `0.07 × ${q} + 30 + ${dao} = ${cost}`
          } else if (this.moqie.moshu > 6 || ((x15 > 600 && x15 <= 720) && (y10 > 720 && y10 <= 1020)) || ((x10 > 720 && x10 <= 930) && (y15 > 600 && y15 <= 635))) {
            cost = 0.08 * q + 30 + dao
            costStr = `0.08 × ${q} + 30 + ${dao} = ${cost}`
          } else if (((x15 > 635 && x15 < 720) && (y10 > 930 && y10 < 1020)) || ((x10 > 930 && x10 < 1020) && (y15 > 635 && y15 < 720))) {
            cost = 0.09 * q + 30 + dao
            costStr = `0.09 × ${q} +30 + ${dao} = ${cost}`
          }
          break
        case '坑盒':
          if (0.07 * q <= 120) {
            cost = 120 + dao
            costStr = `120 + ${dao} = ${cost}`
          } else if (this.moqie.moshu <= 8 || ((x15 <= 600) && (y10 <= 720)) || ((x10 <= 720) && (y15 <= 720))) {
            cost = 0.07 * q + dao
            costStr = `0.07 × ${q} + ${dao} = ${cost}`
          } else if (this.moqie.moshu > 8 || (((x15 > 600) && (x15 <= 720)) && ((y10 < 1020) && (y10 > 780)))) {
            cost = 0.08 * q + dao
            costStr = `0.08 × ${q} + ${dao} = ${cost}`
          } else if ((x15 > 720 || y10 > 1030 || y15 > 720 || x10 > 1030) && (0.2 * q <= 250)) {
            cost = 250 + dao
            costStr = `250 + ${dao} = ${cost}`
          } else if (y10 > 1030 || y15 > 720 || y15 > 720 || x10 > 1030) {
            cost = 0.2 * q
            costStr = `0.2 × ${q} = ${cost}`
          }
          break
      }
      return costStr
    },
    clickToFin () {
      if (!this.disable) this.$emit('transferToFather', 'moqie', this.moqie)
    },
    clickToChange () {
      this.disable = !this.disable
    },
    getRole () {
      return sessionStorage.getItem('roleType') === '1'
    }
  },
  watch: {
    confirm (nV, oV) {
      if (nV !== oV) this.clickToFin()
    }
  }
}
</script>

<style scoped>
.length{
  width: 100px;
  display: inline-block;
  margin-top: 10px;
  margin-right: 10px;
}

.cost{
  margin-top: 10px;
}
</style>
